/**
 * <copyright>
 * </copyright>
 *

 */
package org.xtext.example.cr.cR.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.xtext.example.cr.cR.Array;
import org.xtext.example.cr.cR.ArrayElement;
import org.xtext.example.cr.cR.CRPackage;
import org.xtext.example.cr.cR.CalcCR;
import org.xtext.example.cr.cR.SimpleVariable;
import org.xtext.example.cr.cR.Variable;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Calc CR</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getFunction <em>Function</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getVector <em>Vector</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getArrayElement <em>Array Element</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getArrayElement1 <em>Array Element1</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getVar1 <em>Var1</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getArrayElement2 <em>Array Element2</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.CalcCRImpl#getVar2 <em>Var2</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CalcCRImpl extends MinimalEObjectImpl.Container implements CalcCR
{
  /**
   * The default value of the '{@link #getFunction() <em>Function</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFunction()
   * @generated
   * @ordered
   */
  protected static final String FUNCTION_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getFunction() <em>Function</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFunction()
   * @generated
   * @ordered
   */
  protected String function = FUNCTION_EDEFAULT;

  /**
   * The cached value of the '{@link #getVector() <em>Vector</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVector()
   * @generated
   * @ordered
   */
  protected Array vector;

  /**
   * The cached value of the '{@link #getArrayElement() <em>Array Element</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getArrayElement()
   * @generated
   * @ordered
   */
  protected ArrayElement arrayElement;

  /**
   * The cached value of the '{@link #getArrayElement1() <em>Array Element1</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getArrayElement1()
   * @generated
   * @ordered
   */
  protected ArrayElement arrayElement1;

  /**
   * The cached value of the '{@link #getVar1() <em>Var1</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVar1()
   * @generated
   * @ordered
   */
  protected SimpleVariable var1;

  /**
   * The cached value of the '{@link #getArrayElement2() <em>Array Element2</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getArrayElement2()
   * @generated
   * @ordered
   */
  protected ArrayElement arrayElement2;

  /**
   * The cached value of the '{@link #getVar2() <em>Var2</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVar2()
   * @generated
   * @ordered
   */
  protected Variable var2;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected CalcCRImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return CRPackage.Literals.CALC_CR;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getFunction()
  {
    return function;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setFunction(String newFunction)
  {
    String oldFunction = function;
    function = newFunction;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__FUNCTION, oldFunction, function));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Array getVector()
  {
    if (vector != null && vector.eIsProxy())
    {
      InternalEObject oldVector = (InternalEObject)vector;
      vector = (Array)eResolveProxy(oldVector);
      if (vector != oldVector)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRPackage.CALC_CR__VECTOR, oldVector, vector));
      }
    }
    return vector;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Array basicGetVector()
  {
    return vector;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setVector(Array newVector)
  {
    Array oldVector = vector;
    vector = newVector;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__VECTOR, oldVector, vector));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ArrayElement getArrayElement()
  {
    return arrayElement;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetArrayElement(ArrayElement newArrayElement, NotificationChain msgs)
  {
    ArrayElement oldArrayElement = arrayElement;
    arrayElement = newArrayElement;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__ARRAY_ELEMENT, oldArrayElement, newArrayElement);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setArrayElement(ArrayElement newArrayElement)
  {
    if (newArrayElement != arrayElement)
    {
      NotificationChain msgs = null;
      if (arrayElement != null)
        msgs = ((InternalEObject)arrayElement).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRPackage.CALC_CR__ARRAY_ELEMENT, null, msgs);
      if (newArrayElement != null)
        msgs = ((InternalEObject)newArrayElement).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRPackage.CALC_CR__ARRAY_ELEMENT, null, msgs);
      msgs = basicSetArrayElement(newArrayElement, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__ARRAY_ELEMENT, newArrayElement, newArrayElement));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ArrayElement getArrayElement1()
  {
    return arrayElement1;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetArrayElement1(ArrayElement newArrayElement1, NotificationChain msgs)
  {
    ArrayElement oldArrayElement1 = arrayElement1;
    arrayElement1 = newArrayElement1;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__ARRAY_ELEMENT1, oldArrayElement1, newArrayElement1);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setArrayElement1(ArrayElement newArrayElement1)
  {
    if (newArrayElement1 != arrayElement1)
    {
      NotificationChain msgs = null;
      if (arrayElement1 != null)
        msgs = ((InternalEObject)arrayElement1).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRPackage.CALC_CR__ARRAY_ELEMENT1, null, msgs);
      if (newArrayElement1 != null)
        msgs = ((InternalEObject)newArrayElement1).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRPackage.CALC_CR__ARRAY_ELEMENT1, null, msgs);
      msgs = basicSetArrayElement1(newArrayElement1, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__ARRAY_ELEMENT1, newArrayElement1, newArrayElement1));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public SimpleVariable getVar1()
  {
    if (var1 != null && var1.eIsProxy())
    {
      InternalEObject oldVar1 = (InternalEObject)var1;
      var1 = (SimpleVariable)eResolveProxy(oldVar1);
      if (var1 != oldVar1)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRPackage.CALC_CR__VAR1, oldVar1, var1));
      }
    }
    return var1;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public SimpleVariable basicGetVar1()
  {
    return var1;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setVar1(SimpleVariable newVar1)
  {
    SimpleVariable oldVar1 = var1;
    var1 = newVar1;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__VAR1, oldVar1, var1));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ArrayElement getArrayElement2()
  {
    return arrayElement2;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetArrayElement2(ArrayElement newArrayElement2, NotificationChain msgs)
  {
    ArrayElement oldArrayElement2 = arrayElement2;
    arrayElement2 = newArrayElement2;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__ARRAY_ELEMENT2, oldArrayElement2, newArrayElement2);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setArrayElement2(ArrayElement newArrayElement2)
  {
    if (newArrayElement2 != arrayElement2)
    {
      NotificationChain msgs = null;
      if (arrayElement2 != null)
        msgs = ((InternalEObject)arrayElement2).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRPackage.CALC_CR__ARRAY_ELEMENT2, null, msgs);
      if (newArrayElement2 != null)
        msgs = ((InternalEObject)newArrayElement2).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRPackage.CALC_CR__ARRAY_ELEMENT2, null, msgs);
      msgs = basicSetArrayElement2(newArrayElement2, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__ARRAY_ELEMENT2, newArrayElement2, newArrayElement2));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable getVar2()
  {
    if (var2 != null && var2.eIsProxy())
    {
      InternalEObject oldVar2 = (InternalEObject)var2;
      var2 = (Variable)eResolveProxy(oldVar2);
      if (var2 != oldVar2)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRPackage.CALC_CR__VAR2, oldVar2, var2));
      }
    }
    return var2;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable basicGetVar2()
  {
    return var2;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setVar2(Variable newVar2)
  {
    Variable oldVar2 = var2;
    var2 = newVar2;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.CALC_CR__VAR2, oldVar2, var2));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case CRPackage.CALC_CR__ARRAY_ELEMENT:
        return basicSetArrayElement(null, msgs);
      case CRPackage.CALC_CR__ARRAY_ELEMENT1:
        return basicSetArrayElement1(null, msgs);
      case CRPackage.CALC_CR__ARRAY_ELEMENT2:
        return basicSetArrayElement2(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case CRPackage.CALC_CR__FUNCTION:
        return getFunction();
      case CRPackage.CALC_CR__VECTOR:
        if (resolve) return getVector();
        return basicGetVector();
      case CRPackage.CALC_CR__ARRAY_ELEMENT:
        return getArrayElement();
      case CRPackage.CALC_CR__ARRAY_ELEMENT1:
        return getArrayElement1();
      case CRPackage.CALC_CR__VAR1:
        if (resolve) return getVar1();
        return basicGetVar1();
      case CRPackage.CALC_CR__ARRAY_ELEMENT2:
        return getArrayElement2();
      case CRPackage.CALC_CR__VAR2:
        if (resolve) return getVar2();
        return basicGetVar2();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case CRPackage.CALC_CR__FUNCTION:
        setFunction((String)newValue);
        return;
      case CRPackage.CALC_CR__VECTOR:
        setVector((Array)newValue);
        return;
      case CRPackage.CALC_CR__ARRAY_ELEMENT:
        setArrayElement((ArrayElement)newValue);
        return;
      case CRPackage.CALC_CR__ARRAY_ELEMENT1:
        setArrayElement1((ArrayElement)newValue);
        return;
      case CRPackage.CALC_CR__VAR1:
        setVar1((SimpleVariable)newValue);
        return;
      case CRPackage.CALC_CR__ARRAY_ELEMENT2:
        setArrayElement2((ArrayElement)newValue);
        return;
      case CRPackage.CALC_CR__VAR2:
        setVar2((Variable)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case CRPackage.CALC_CR__FUNCTION:
        setFunction(FUNCTION_EDEFAULT);
        return;
      case CRPackage.CALC_CR__VECTOR:
        setVector((Array)null);
        return;
      case CRPackage.CALC_CR__ARRAY_ELEMENT:
        setArrayElement((ArrayElement)null);
        return;
      case CRPackage.CALC_CR__ARRAY_ELEMENT1:
        setArrayElement1((ArrayElement)null);
        return;
      case CRPackage.CALC_CR__VAR1:
        setVar1((SimpleVariable)null);
        return;
      case CRPackage.CALC_CR__ARRAY_ELEMENT2:
        setArrayElement2((ArrayElement)null);
        return;
      case CRPackage.CALC_CR__VAR2:
        setVar2((Variable)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case CRPackage.CALC_CR__FUNCTION:
        return FUNCTION_EDEFAULT == null ? function != null : !FUNCTION_EDEFAULT.equals(function);
      case CRPackage.CALC_CR__VECTOR:
        return vector != null;
      case CRPackage.CALC_CR__ARRAY_ELEMENT:
        return arrayElement != null;
      case CRPackage.CALC_CR__ARRAY_ELEMENT1:
        return arrayElement1 != null;
      case CRPackage.CALC_CR__VAR1:
        return var1 != null;
      case CRPackage.CALC_CR__ARRAY_ELEMENT2:
        return arrayElement2 != null;
      case CRPackage.CALC_CR__VAR2:
        return var2 != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (function: ");
    result.append(function);
    result.append(')');
    return result.toString();
  }

} //CalcCRImpl
